package com.waimai.utils;

import java.util.ArrayList;

import com.waimai.entity.Sale;
import com.waimai.log.Log;

public class htmlStrUtils {
	public static ArrayList<Sale> getEleSaleList(String saleString) {
		ArrayList<Sale> List = new ArrayList<Sale>();
		ArrayList<String> strList = new ArrayList<String>();
		try {

			String newString = StringUtils.pattern(saleString, "在线支付.*\"");
			if (newString.length() > 5) {
				newString = newString.substring(4, newString.length() - 1);
				String[] strs = newString.split("，");
				for (int l = 0; l < strs.length; l++) {
					if (strs[l].length() != 0) {
						strList.add(strs[l]);
					}
				}
				for (String s : strList) {
					String[] s1 = s.split("减");
					String man = s1[0];
					man = man.substring(1, man.length());
					int newMan = Integer.parseInt(man);
					int jian = Integer.parseInt(s1[1]);
					List.add(new Sale(newMan, jian));
				}
			}
		} catch (ArrayIndexOutOfBoundsException e) {
			Log.e(e, "eleUtls getSaleList error");
			e.printStackTrace();

		} catch (IndexOutOfBoundsException e) {
			Log.e(e, "eleUtls getSaleList error");
			e.printStackTrace();
		}
		return List;
	}

	public static ArrayList<Sale> getMeituanSaleList(String str) {
		str = StringUtils.replaceBlank(str);
		str = str.substring(0, str.length() - 8);
		ArrayList<Sale> array = new ArrayList<Sale>();
		ArrayList<String> strList = new ArrayList<String>();
		try {
			String[] strs = str.split(";");
			for (int i = 0; i < strs.length; i++) {
				if (strs[i].length() != 0) {
					strList.add(strs[i]);
				}
			}
			for (String s : strList) {
				String[] s1 = s.split("满");
				if (s1.length < 2) {
					continue;
				}
				String[] ss = s1[1].split("减");
				int man = Integer.parseInt(ss[0].substring(0,
						ss[0].length() - 1));
				int jian = Integer.parseInt(ss[1].substring(0,
						ss[1].length() - 1));
				array.add(new Sale(man, jian));
			}
		} catch (ArrayIndexOutOfBoundsException e) {
			Log.e(e, "meituanUtls getSaleList error");
			e.printStackTrace();
		} catch (IndexOutOfBoundsException e) {
			Log.e(e, "meituanUtls getSaleList error");
			e.printStackTrace();
		}
		return array;
	}

	public static String getMeituanHref(String hrefText) {
		String result = "";
		result = StringUtils.pattern(hrefText.split(" ")[1], "\".*\"");
		result = result.substring(1, result.length() - 1);
		return result;
	}

	public static String getMeituanImgUrl(String imgText) {
		imgText = StringUtils.pattern(imgText.split(" ")[3], "http.*\"");
		return imgText.substring(0, imgText.length() - 1);
	}

}
